package com.iiiss.template.ssh.impl.controllers;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.iiiss.template.ssh.core.beans.IExampleEvent;
import com.iiiss.template.ssh.core.services.IExampleEventService;

/*
 * TemplateSSH - com.iiiss.template.ssh.impl.controllers - ExampleEventController.java
 * 
 * Copyright (C) 2011  Mingye Cheng <Cheng, Mingye at GMAIL>
 * 
 * ExampleEventController.java is part of <iiiStudio Template Framework> project.
 * This project is hosted at <http://iiiss-template-ssh.googlecode.com>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Revision history:
 * [2011-5-30] Mingye Cheng - Initial version established.
 */
@Controller
public class ExampleEventController {
	@Autowired
	private IExampleEventService exampleEventService;

	@RequestMapping(value = "/event", method = RequestMethod.GET)
	public String example(Model model) {
		IExampleEvent event = exampleEventService.triggerRandomEvent();
		model.addAttribute("originalItem", event);

		IExampleEvent idEvent = exampleEventService.acquireEvent(event.getKey());
		model.addAttribute("idItem", idEvent);

		IExampleEvent titleEvent = exampleEventService.acquireEvent(event.getTitle());
		model.addAttribute("titleItem", titleEvent);

		List<IExampleEvent> results = exampleEventService.listAllEvents();
		model.addAttribute("list", results);
		return "example";
	}
}
